package com.xm.controller;

import com.xm.common.pojo.JsonResult;
import com.xm.pojo.Role;
import com.xm.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping("/role/")
@RestController
public class RoleController {
    @Autowired
    RoleService roleService;

    @PostMapping
    JsonResult doSaveRole(@RequestBody Role role){
            roleService.saveRole(role);
            return new JsonResult("save ok");
    }

    @DeleteMapping("{id}")
    JsonResult doDeleteRole(@PathVariable Integer id){
            roleService.deleteById(id);
            return new JsonResult("delete ok");
    }

    @PutMapping
    JsonResult doUpdateRole(@RequestBody Role role){
            int row= roleService.updateRole(role);
            return new JsonResult("update ok");
    }

    @GetMapping
    JsonResult doFindRole(Role role){
        return new JsonResult(roleService.findRole(role));
    }

    @GetMapping("{id}")
    JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(roleService.findById(id));
    }

}
